﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    partial class ClassRoom
    {
        public bool IsValid
        {
            get
            {
                return (GetRuleViolations().Count() == 0);
            }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {

            if (Campus == null)
                yield return new RuleViolation("Campus is required", "Campus");

            if (String.IsNullOrEmpty(ClassRoomName))
                yield return new RuleViolation("ClassRoom is required", "ClassRoomName");

            yield break;
        }

        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (!IsValid)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }
}